<!--
 * @Description:
 * @Author: zhailei
 * @Date: 2021-08-16 17:45:49
 * @LastEditTime: 2021-08-16 17:55:05
 * 
 * @FilePath: \vite-demoe:\wwwroot\Vue\\-cloud-vue\src\pages\workflow\actForm\masterEdit.vue
-->
<template>
  <t-modal
    :title="title"
    :width="640"
    :visible="visible"
    :switchFullscreen="true"
    :confirmLoading="loading"
    @ok="
      () => {
        $emit('ok');
      }
    "
    @cancel="
      () => {
        $emit('cancel');
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form :form="form">
        <a-form-item class="hiddenItem">
          <!-- uuid隐藏 -->
          <a-input v-decorator="['uuid']" disabled type="hidden" />
        </a-form-item>
        <a-form-item
          :label="$ct('FormName', '表单名称')"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input
            v-decorator="[
              'name',
              { rules: [{ required: true, message: '必填！' }] },
            ]"
          />
        </a-form-item>
        <a-form-item
          :label="$ct('FormCode', '表单编码')"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input
            v-decorator="[
              'code',
              { rules: [{ required: true, message: '必填！' }] },
            ]"
          />
        </a-form-item>
        <a-form-item
          :label="$ct('FormStatus', '表单状态')"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-switch
            default-checked
            v-decorator="['status', { initialValue: true }]"
          />
        </a-form-item>
        <a-form-item
          :label="$ct('PCPagePath', 'pc端页面路径')"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input
            v-decorator="[
              'nodeFormPath',
              { rules: [{ required: true, message: '必填！' }] },
            ]"
          />
        </a-form-item>
        <a-form-item
          :label="$ct('AppPagePath', 'app端页面路径')"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input
            v-decorator="[
              'appPagePath',
              { rules: [{ required: true, message: '必填！' }] },
            ]"
          />
        </a-form-item>
        <a-form-item
          :label="$ct('SaveAddress', '保存地址')"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input
            v-decorator="[
              'nodeFormSavePath',
              { rules: [{ required: true, message: '必填！' }] },
            ]"
          />
        </a-form-item>
        <a-form-item
          :label="$ct('UpdateAddress', '更新地址')"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input
            v-decorator="[
              'nodeFormUpdatePath',
              { rules: [{ required: true, message: '必填！' }] },
            ]"
          />
        </a-form-item>
        <a-form-item
          :label="$ct('DetailedAddress', '详情地址')"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input
            v-decorator="[
              'nodeFormEditPath',
              { rules: [{ required: true, message: '必填！' }] },
            ]"
          />
        </a-form-item>
        <a-form-item
          :label="$ct('ProcessAddress', '流程地址')"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input
            v-decorator="[
              'nodeFormCompletePath',
              { rules: [{ required: true, message: '必填！' }] },
            ]"
          />
        </a-form-item>
      </a-form>
    </a-spin>
  </t-modal>
</template>

<script>
import pick from "lodash.pick";
// 表单字段
const fields = [
  "uuid",
  "name",
  "code",
  "status",
  "nodeFormPath",
  "appPagePath",
  "nodeFormEditPath",
  "nodeFormCompletePath",
  "nodeFormUpdatePath",
  "nodeFormSavePath",
];
export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    loading: {
      type: Boolean,
      default: () => false,
    },
    model: {
      type: Object,
      default: () => null,
    },
  },
  data() {
    return {
      title: "",
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      form: this.$form.createForm(this),
    };
  },
  methods: {},
  created() {
    // 防止表单未注册
    fields.forEach((v) => this.form.getFieldDecorator(v));
    // 当 model 发生改变时，为表单设置值
    this.$watch("model", () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields));
    });
  },
};
</script>
